<!--
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body  bgcolor="#e0e0e0">
-->
<?php
require_once 'inc/mysql.inc.php';

$result = mysql_query("SELECT * FROM People WHERE `:active`=1 ORDER BY `People`.`:last` ASC;");
$filename = "/Volumes/City/Workgroup/Vogoni/Public/Exporty/Ustav.inst";
$fh = fopen($filename, 'w');
if ($fh == FALSE){
  echo "Chyba";
} else {
fwrite($fh, "\xEF\xBB\xBF"."(:name \"Matematický ústav\" :workers (\n");
while ($row = mysql_fetch_array($result)) {
    fwrite($fh, "(:name (\"". $row[':first']."\" \"".$row[':midle']."\" \"".$row[':last']."\" \"".$row[':degree-before']."\" \"".$row[':degree-after']."\") ");
    fwrite($fh, ":schedule-alias \"".$row[':schedule-alias']."\" ");
    fwrite($fh, ":work-load ".$row[':work-load']." ");
    if($row[':forms'] & 1) { $single = ":single";}else{$single="";}
    if($row[':forms'] & 2) { $kumula = ":kumula";}else{$kumula="";}
    fwrite($fh, ":forms (".$single." ".$kumula.") ");
 
    $grantsResult = mysql_query("SELECT * FROM PeopleInProjects WHERE person=".$row['id'].";") or die("koko");
    fwrite($fh, " :grants ("); 
    while ($grant = mysql_fetch_array($grantsResult)) {
        fwrite($fh, "(");
//        echo $grant['project'];
        $grantdescr=mysql_fetch_array(mysql_query("SELECT * FROM projects WHERE id=".$grant['project'].";"));
        fwrite($fh, "\"".$grantdescr['Name']."\" ");
        fwrite($fh, $grant[':work-load']);
        fwrite($fh, ") ");
    }
    fwrite($fh, ") ");
    fwrite($fh, ":type ".$row[':type']." ");
    $Po = ""; $Ut = ""; $St = ""; $Ct = ""; $Pa = "";
    if($row[':exclude'] & 1) $Po = $row[':exclude'] & 1;
    if($row[':exclude'] & 2) $Ut = $row[':exclude'] & 2;
    if($row[':exclude'] & 4) $St = $row[':exclude'] & 3;
    if($row[':exclude'] & 8) $Ct = $row[':exclude'] & 4;
    if($row[':exclude'] & 16) $Pa = $row[':exclude'] & 5;

    fwrite($fh, ":exclude (".$Po." ".$Ut." ".$St." ".$Ct." ".$Pa.")");
    fwrite($fh, ")\n");
}
fwrite($fh, "))");
fclose($fh);
echo "Ustav vyexporovan.";
}
?>
<!--
Hotovo.

</body>
</html>
-->